<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>

    <script src="../lib/react.js"></script>
    <script src="../lib/react-dom.js"></script>
    <script src="../lib/babel.js"></script>

    <script type="text/babel">
      // 1.定义App根组件
      class App extends React.Component {
        constructor() {
          super(); //继承了就要调用super
          this.state = {
            //数据固定放在state中
            title: "哈哈",
            imgURL:
              "https://p5.img.cctvpic.com/photoworkspace/contentimg/2023/03/30/2023033011303020756.jpg",
            href: "http://www.baidu.com",

            isActice: true,
            objStyle: { color: "red", fontSize: "30px" },
          };
        }

        render() {
          const { title, imgURL, href, isActice, objStyle } = this.state;

          // 需求：isActice为true时，添加active类名，否则不加
          // 1.class绑定的写法一：
          const className = `abc cba ${isActice ? "active" : ""}`;
          // 2.class绑定的写法二：将所有的class放到数组中
          const classList = ["abc", "cba"];
          if (isActice) {
            classList.push("active");
          }
          // 3.class绑定的写法三：第三方库classnames
          return (
            <div>
              {/*1.基本绑定*/}
              <h2 title={title}>我是h2属性</h2>
              <img src={imgURL} alt="" />
              <a href={href}>百度一下</a>

              {/*2.绑定class属性: 最好使用className*/}
              <h2 className={className}>哈哈哈</h2>
              <h2 className={classList.join(" ")}>哈哈哈</h2>

              {/* 3.绑定style属性:绑定对象类型 */}
              <h2 style={{ color: "red", fontSize: "30px" }}>会会会会会好</h2>
              <h2 style={objStyle}>会会会会会好</h2>
            </div>
          );
        }
      }

      // 1.创建root并且渲染App组件
      const root = ReactDOM.createRoot(document.querySelector("#root"));
      root.render(<App />);
    </script>
  </body>
</html>
